#include "quicksort.h"
static void swap(int array[], int low, int high)
{
        int temp = array[low];
        array[low] = array[high];
        array[high] = temp;
}
//划分过程 第一个元素当
static int partition(int array[], int low, int high)
{
        int pv = array[low];
        while (low < high){
                while ((low < high) && (array[high] >= pv)){
                        high--; //比基数大,本来就在右边,所以high前移动
                }
                swap(array,low,high);
                while ((low < high) && (array[high] <= pv)){
                        low++;
                }
                swap(array,low,high);
        }
        //返回极轴的位置
        return low;
}
static void QSort(int array[], int low, int high)
{
        if (low < high){
                //选一个py值,把数据分别放在py值的左右两边
                int pivot = partition(array, low, high);
                //对子序列1排序
                QSort(array,low,pivot-1);   
                //对子序列2排序
                QSort(array,pivot+1,high);   
        }
}
//TODO 有问题
void quickSort(int array[], int len)
{
        QSort(array,0,len-1);
}